import time,random

robot_name = ['ro1','ro2','ro3','ro4','ro5','ro6']
player_name = ['王迎','范少华','范鸿忠','张晶','王金明','郑淑琴']

player_choice = random.sample(player_name,3)
robot_choice = random.sample(robot_name,3)

robot = {}
player = {}

def make_info():
    blood = random.randint(100,150)
    fight = random.randint(30,50)

    return blood,fight

def show_info():
    print('-------------------- 玩家信息 --------------------')
    for i in range(3):

        robot[robot_choice[i]] = make_info()

        print('敌方：%s血量：%d，战斗力：%d' %(robot_choice[i],robot[robot_choice[i]][0],robot[robot_choice[i]][1]))

    print('------------------------------')



def order_rule():

    global player_choice
    player_dict = {}

    for i in range(3):
        order = int(input('你想将 %s 放在第几个上场？(输入1-3)' %(player_choice[i])))

        player_dict[order] = player_choice[i]


    player_choice = []
    for i in range(1,4):
        player_choice.append(player_dict[i])


    print('\n我方角色出场顺序是：%s、%s、%s' %(player_choice[0],player_choice[1],player_choice[2]))
    print('敌方角色出场顺序是：%s、%s、%s' %(robot_choice[0],robot_choice[1],robot_choice[2]))


def pk_rule():

    round = 1
    score = 0
    player = {}
    for j in range(3):

        player[player_choice[j]] = make_info()

    for i in range(3):
        playerName = player_choice[i]
        robotName = robot_choice[i]

        player_blood = player[player_choice[i]][0]
        player_fight = player[player_choice[i]][1]

        robot_blood = robot[robot_choice[i]][0]
        robot_fight = robot[robot_choice[i]][1]


        print('\n-------------------- 【第%d局】--------------------'%(round))
        print('玩家角色：%s  vs  敌方角色：%s'%(playerName,robotName))
        print('%s 血量：%d  攻击：%d'%(playerName,player_blood,player_fight))
        print('%s 血量：%d  攻击：%d'%(robotName,robot_blood,robot_fight))
        input('请按回车键继续。\n')


        while player_blood > 0 and robot_blood > 0:
            robot_blood = robot_blood - player_fight
            player_blood = player_blood - robot_fight

            print('%s 发起了进攻，%s 剩余血量：%d'%(playerName,robotName,robot_blood))
            print('%s 发起了进攻，%s 剩余血量：%d'%(robotName,playerName,player_blood))
            print('--------------------------------------------------')
            time.sleep(1)
        else:
            if player_blood > 0 and robot_blood <= 0:
                print('\n敌人挂了，你赢了！！')
                score += 1

            elif player_blood <=0 and robot_blood > 0:
                print('\n你被敌人干死了，哈哈！！')
                score += -1

            else:
                print('哎，你们俩平局')
                score += 0

            round += 1

    input('\n点击回车，查看比赛的最终结果\n')
    if score > 0:
        print('【最终结果：你赢了！】\n')
    elif score < 0:
        print('【最终结果：你输了！】\n')
    else:
        print('【最终结果：平局！】\n')



def main():
    show_info()
    order_rule()
    pk_rule()


main()
